<%@include file="../template/configuration.jsp" %>
<%@page import="models.Employee"%>
<%@page import="dao.EmployeeDao"%>
<%@page import="java.util.List"%>
<%@page import="classes.HibernateUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
    if (request.getParameter("page") != null) {
        HibernateUtil hu = new HibernateUtil();
        EmployeeDao cd = new EmployeeDao(hu.openSession());
        List<Employee> employees = cd.getPagination(Integer.parseInt(request.getParameter("page")));
        pageContext.setAttribute("employees", employees);
    }
%>
<table class="overview" id="search-table">
    <thead>
        <tr>
            <th class="single-icon"></th>
            <th>${uq_full_name}</th>
            <th>${uq_description}</th>
            <th>${uq_email}</th>
            <th>${uq_courses}</th>
            <th class="date">${uq_added}</th>
            <th class="manage">${uq_manage}</th>
        </tr>
    </thead>
    <tbody>
        <c:set var="i" value="0"/>
        <c:forEach items="${employees}" var="employees">
            <c:set var="i" value="${i + 1}"/>
            <tr class="<c:choose><c:when test="${i % 2 == 0}">even</c:when><c:otherwise>odd</c:otherwise></c:choose>">
                <td><c:if test="${!employees.removable}"><img src="${url}images/admin.png"/></c:if></td>
                <td><a href="">${employees.firstname} ${employees.insertion} ${employees.lastname}</a></td>
                <td>
                    <c:choose>
                        <c:when test="${fn:length(employees.description) > 40}">
                            <c:out value="${fn:substring(employees.description, 0, 40)}"/>...
                        </c:when>
                        <c:otherwise>
                            ${employees.description}
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>${employees.user.email}</td>
                <td>
                    <img src="${url}images/question.png" class="question" />
                    <div class="relative">
                        <div class="tooltip">
                            <c:forEach items="${courses}" var="courses">
                                <c:forEach items="${courses.teacher}" var="courseteacher">
                                    <c:choose>
                                        <c:when test="${courseteacher.id==employees.id}">${courses.name}</br></c:when>
                                    </c:choose>
                                </c:forEach>
                            </c:forEach>
                        </div>
                    </div>
                </td>
                <td>${employees.user.date}</td>
                <td><a href="${url}Teacher/edit?id=${employees.id}"><img src="${url}images/edit.png"/></a> 
                        <c:if test="${employees.removable}">
                        <a href="${url}Teacher/remove?idremove=${employees.id}" class="remove"><img src="${url}images/remove.png"/></a>
                        <span class="info">teacher <strong>${employees.firstname} ${employees.insertion} ${employees.lastname}</strong></span>
                    </c:if>                                            
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>